package edu.pdx.cs.cs542s07.minichess;

/**
 * Contains the necessary data for a minichess move.
 * @author Michael C Smith <maxomai at gmail dot com>
 */
class Move implements Comparable<Move> {
	
	private Square from, to;
	private int score = 0;
	
	public static final Move RESIGN = new Move(new Square(-1, -1), new Square(-1, -1));
	
	/**
	 * @param from	Square from which piece moves
	 * @param to	Square to which piece moves
	 */
	Move(Square from, Square to) {
		super();
		this.from = from;
		this.to = to;
	}

	Square getFrom() {
		return from;
	}

	Square getTo() {
		return to;
	}
	
	void setScore(int score) {
		this.score = score;
	}
	
	int getScore() {
		return this.score;
	}
	
	public String toString() {
		StringBuffer buff = new StringBuffer();
		buff.append((char)(from.col + 'a'));
		buff.append((char)(from.row + '1'));
		buff.append('-');
		buff.append((char)(to.col + 'a'));
		buff.append((char)(to.row + '1'));
		return buff.toString();		
	}
	
	public boolean equals(Move m) {
		return (m.from.row == this.from.row && m.from.col == this.from.col &&
				m.to.row == this.to.row 	&& m.to.col == this.to.col);
	}
	
	public int compareTo(Move m) {
		//return this.score-m.getScore();
		return m.getScore()-this.score;
	}
	
	public boolean isResign() {
		return (from.row == -1); 
	}
	
}
